1
|
|
|
import GoogleMapEditor from './blocks/maps/modules/GoogleMapEditor'; |
2
|
|
|
|
3
|
|
|
(function ($) { |
4
|
|
|
$.entwine('ss', function ($) { |
5
|
|
|
$('*[data-module="editor"]').entwine({ |
6
|
|
|
onmatch: function () { |
7
|
|
|
|
8
|
|
|
window.editor = { |
9
|
|
|
readyApi: false, |
10
|
|
|
instance: null, |
11
|
|
|
api: $(this).data('key'), |
12
|
|
|
init: () => { |
13
|
|
|
window.editor.instance = new GoogleMapEditor($(this)[0], { |
14
|
|
|
closures: { |
15
|
|
|
onMarkerPlaced: (instance, marker) => { |
16
|
|
|
$.ajax({ |
17
|
|
|
url: $(this).data('update-marker-link'), |
18
|
|
|
method: 'GET', |
19
|
|
|
data: marker.getData() |
20
|
|
|
}) |
21
|
|
|
}, |
22
|
|
|
onMarkerSave: (instance, marker) => { |
23
|
|
|
$.ajax({ |
24
|
|
|
url: $(this).data('update-marker-link'), |
25
|
|
|
method: 'GET', |
26
|
|
|
data: marker.getData() |
27
|
|
|
}) |
28
|
|
|
}, |
29
|
|
|
onMarkerDelete: (instance, marker) => { |
30
|
|
|
$.ajax({ |
31
|
|
|
url: $(this).data('delete-marker-link'), |
32
|
|
|
method: 'GET', |
33
|
|
|
data: { |
34
|
|
|
InstanceId: marker.options.instanceId |
35
|
|
|
} |
36
|
|
|
}) |
37
|
|
|
}, |
38
|
|
|
onZoomChanged: (instance, zoomLevel) => { |
39
|
|
|
$.ajax({ |
40
|
|
|
url: $(this).data('zoom-changed-link'), |
41
|
|
|
method: 'GET', |
42
|
|
|
data: { |
43
|
|
|
zoom: zoomLevel |
44
|
|
|
} |
45
|
|
|
}) |
46
|
|
|
}, |
47
|
|
|
onCoordinatesChanged: (instance, coordinates) => { |
48
|
|
|
$.ajax({ |
49
|
|
|
url: $(this).data('coordinates-changed-link'), |
50
|
|
|
method: 'GET', |
51
|
|
|
data: { |
52
|
|
|
coordinates: coordinates |
53
|
|
|
} |
54
|
|
|
}) |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
}); |
58
|
|
|
} |
59
|
|
|
}; |
60
|
|
|
|
61
|
|
|
if (!window.editor.readyApi) { |
62
|
|
|
if ($('#google-maps-api').length <= 0) { |
63
|
|
|
let script = document.createElement('script'); |
64
|
|
|
|
65
|
|
|
script.id = 'google-maps-api'; |
66
|
|
|
script.type = 'text/javascript'; |
67
|
|
|
script.src = `//maps.googleapis.com/maps/api/js?key=${window.editor.api}&libraries=places&callback=window.editor.init`; |
68
|
|
|
|
69
|
|
|
document.body.appendChild(script); |
70
|
|
|
window.editor.readyApi = true; |
71
|
|
|
} else { |
72
|
|
|
window.editor.readyApi = true; |
73
|
|
|
window.editor.init(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
}); |
78
|
|
|
}); |
79
|
|
|
})(jQuery); |